# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=onig
_fullname=oniguruma
pkgbase=mingw-w64-${_fullname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_fullname}"
pkgver=6.9.8
pkgrel=1
pkgdesc="A regular expressions library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('BSD')
url="https://github.com/kkos/oniguruma"
options=('staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/kkos/${_fullname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        0001-onig-config-win-paths.patch)
sha256sums=('28cd62c1464623c7910565fb1ccaaa0104b2fe8b12bcd646e81f73b47535213e'
            '0163df619698fc1a25733db63538a2e65bdfdc5b19383f1d8bca50d5bbfff0f1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver%.1}"
  patch -p1 -i "${srcdir}/0001-onig-config-win-paths.patch"

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver%.1}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-shared \
      --enable-static \
      --enable-posix-api

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"

  rm -fv "${pkgdir}${MINGW_PREFIX}/lib/libonig.def"

  install -vDm644 "${srcdir}/${_realname}-${pkgver%.1}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
